package com.xidian.zhiancloud.controller.cgs.TrainManager;

import com.github.pagehelper.Page;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.Information;
import com.xidian.zhiancloud.model.TrainType;
import com.xidian.zhiancloud.service.cgs.TrainManager.TrainTypeService;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 教育培训-培训类型管理
 * @Author chenguosong
 * @Date 2020/11/24 17:23
 * @Mail 2581592671@qq.com
 */
@RestController
@RequestMapping("/TrainType")
public class TrainTypeController {
    @Autowired
    private TrainTypeService trainTypeService;
    
   //添加类型
    @PostMapping("/add")
    public ResultDTO add(@RequestBody TrainType trainType) {
        trainTypeService.add(trainType);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    @DeleteMapping("/{id}")
    public ResultDTO deleteById(@PathVariable Long id) {
        trainTypeService.deletebyid(id);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
  // 查找类型集合
    @GetMapping("/getList")
    public ResultDTO list(TrainType trainType) {
    	Page<TrainType> pagedata =  trainTypeService.getListPlan(trainType);
    	Map<String, Object> data = new HashMap<String, Object>();
		data.put("datalist", pagedata);
		data.put("PageNum", pagedata.getPageNum());
		data.put("PageSize", pagedata.getPageSize());
		data.put("PageTotal", pagedata.getPages());
		data.put("total", pagedata.getTotal());
		return ResultDTO.successOf(data,GeneralResponseEnums.SUCCESS);
       // return ResultDTO.successOf(trainTypeService.getListPlan(trainType), GeneralResponseEnums.SUCCESS);
    }
  //更新类型
    @PostMapping("/update")
    public ResultDTO update(@RequestBody TrainType trainType) {
        trainTypeService.update(trainType);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
    
    //批量删除类型
    @GetMapping("/remove")
    public ResultDTO remove( @RequestParam("ids") Long[] ids)
    {
    	trainTypeService.deleteTypeByIds(ids);
    	return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
}
